<?php
class Admin_Form_AddProduct extends Apps_Form {
	public function init() {
	    $dataMaper 	= new Model_Tool_DataMapper();

	    $sCategory = array();
	    $tbCategory = new Model_DbTable_ProductCategory();

	    $parentCategory = $tbCategory->fetchAll(array('parent_id =?' => 0, 'status =?' => $tbCategory::STATUS_ACTIVE));
        if($parentCategory) {
            $parentCategory = $parentCategory->toArray();
            foreach ($parentCategory as $key => $value) {
                $childCategory = $tbCategory->fetchAll(array('parent_id =?' => $value['id'], 'status =?' => $tbCategory::STATUS_ACTIVE));
                $sCategory[$value['title']] = $dataMaper->mapKeyValue($childCategory, 'id', 'title');
            }
        }

	    $category = new Zend_Form_Element_Select(
	            'product_category_id',
	            array('label'        => 'Category',
	                  'required'     => true,
                      'multiOptions' => $sCategory
	            ));

	    $tbStatus = new Model_DbTable_ProductStatus();
	    $productStatus = new Zend_Form_Element_Select(
	            'product_status_id',
	            array('label'        => 'Status',
	                  'required'     => true,
                      'multiOptions' => $dataMaper->mapKeyValue(
                            $tbStatus->fetchAll(array('status =?' => $tbStatus::STATUS_ACTIVE)),
                            'id',
                            'title'
                      )
	            ));


	    // Color Product
	    $tbColor = new Model_DbTable_ProductColor();
	    $color = new Zend_Form_Element_MultiCheckbox(
	            'product_color_id',
	            array('label'        => 'Color',
	                  'class'        => 'multi-checkbox',
                      'multiOptions' => $dataMaper->mapKeyValue(
                            $tbColor->fetchAll(array('status =?' => $tbColor::STATUS_ACTIVE)),
                            'id',
                            'title'
                      )
	            ));
	    $color->setSeparator('');

	    $tbSize = new Model_DbTable_ProductSize();
	    $size = new Zend_Form_Element_MultiCheckbox(
	            'product_size_id',
	            array('label'        => 'Size',
	                  'class'        => 'multi-checkbox',
                      'multiOptions' => $dataMaper->mapKeyValue(
                            $tbSize->fetchAll(array('status =?' => $tbSize::STATUS_ACTIVE)),
                            'id',
                            'title'
                      )
	            ));
	    $size->setSeparator('');

	    $isNew = new Zend_Form_Element_Select(
	            'is_new',
	            array('label'        => 'New ?',
	                  'required'     => true,
                      'multiOptions' => array(1 => 'Yes', 0 => 'No')
	            ));

	    $isSellOff = new Zend_Form_Element_Select(
	            'is_sale_off',
	            array('label'        => 'Sell Off ?',
	                  'required'     => true,
                      'multiOptions' => array(0 => 'No', 1 => 'Yes')
	            ));

		$title = new Zend_Form_Element_Text(
				'name',
				array('label' 	 => 'Name',
				      'required' => true));

		$code = new Zend_Form_Element_Text(
				'code',
				array('label' 	 => 'Code',
				      'required' => true));

		$priceOrigine = new Zend_Form_Element_Text(
				'price_original',
				array('label' 	 => 'Price Original'));

		$priceSell = new Zend_Form_Element_Text(
				'price_sale',
				array('label' 	 => 'Price Sell'));

		$priceSellOff = new Zend_Form_Element_Text(
				'price_sale_off',
				array('label' 	 => 'Price Sell Off'));

		$thumbnail = new Zend_Form_Element_File(
		        'thumbnail_link',
		        array('label' => 'Thumbnail'));

		$thumbnail->setMaxFileSize('5242880')
		          ->addDecorator('Mimetype', false, array('image/jpg', 'image/jpeg', 'image/png'))
		          ->addValidator('Extension', false, array('jpg', 'jpeg', 'png'));

		$images = new Zend_Form_Element_File(
		        'images',
		        array('label' => 'Images', 'style' => 'display:block'));

		$images->setMaxFileSize('5242880')
		       ->setMultiFile(15)
	           ->addDecorator('Mimetype', false, array('image/jpg', 'image/jpeg', 'image/png'))
	           ->addValidator('Extension', false, array('jpg', 'jpeg', 'png'));

		$status = new Zend_Form_Element_Select(
		        'status',
		        array('label'      => 'Public',
		              'required'     => true,
		              'multiOptions' => array(1 => 'Yes', 0 => 'No')));

		$quantity = new Zend_Form_Element_Text(
		        'quantity',
		        array('label'      => 'Quantity',
		              'class'      => 'input-mini'));
		$quantity->addValidator(new Zend_Validate_Digits());

		$sortingNumber = new Zend_Form_Element_Text(
		        'sorting_number',
		        array('label'      => 'Sorting Number',
		              'class'      => 'input-mini'));

		$description = new Zend_Form_Element_Textarea(
		        'description',
		        array('label' 		=> 'Description',
					  'rows'	=> 5,
					  'cols'	=> 80));

		$detail = new Zend_Form_Element_Textarea(
		        'detail',
		        array('label' 		=> 'Detail',
					  'rows'	=> 5,
					  'cols'	=> 80));

		$metaKeyWord = new Zend_Form_Element_Textarea(
		        'meta_keyword',
		        array('label' 		=> 'Meta Keyword',
					  'rows'	=> 5,
					  'cols'	=> 80));

		$metaDescription = new Zend_Form_Element_Textarea(
		        'meta_description',
		        array('label' 		=> 'Meta Description',
					  'rows'	=> 5,
					  'cols'	=> 80));
		$headerTitle = new Zend_Form_Element_Textarea(
		        'header_title',
		        array('label' 		=> 'Header Title',
					  'rows'	=> 5,
					  'cols'	=> 80));


		$this->addElement($category)
			 ->addElement($title)
			 ->addElement($code)
			 ->addElement($priceOrigine)
			 ->addElement($priceSell)
			 ->addElement($priceSellOff)
			 ->addElement($thumbnail)
			 ->addElement($images)
			 ->addElement($status)
			 ->addElement($isNew)
			 ->addElement($isSellOff)
			 ->addElement($productStatus)
			 ->addElement($color)
			 ->addElement($size)
			 ->addElement($quantity)
			 ->addElement($sortingNumber)
			 ->addElement($description)
			 ->addElement($detail)
			 ->addElement($metaKeyWord)
			 ->addElement($metaDescription)
			 ->addElement($headerTitle);

		$this->setLegend('Add New Product Category');
		$this->addActionGroup()
			 ->makeup();
	}
}